﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.Modeling;
using Microsoft.VisualStudio.Modeling.Diagrams;
using VsxFactory.Modeling;

namespace VsxFactory.Modeling
{
    /// <summary>
    /// 
    /// </summary>
    public interface IMultiViewDiagram
    {
        /// <summary>
        /// Synchronizes the diagram.
        /// </summary>
        /// <param name="context">The context.</param>
        void Synchronize(MultiViewContext context);
    }

    /// <summary>
    /// 
    /// </summary>
    public class MultiViewContext
    {
        public string DiagramName { get; set; }
        public string PhysicalViewName { get { return DiagramName + "|" + RootElementId.ToString("B"); } }
        public Guid RootElementId { get; set; }
        public string Caption { get; set; }

        public bool CheckDiagram(Diagram diagram)
        {
            return diagram != null && diagram.ModelElement != null && PhysicalViewName == diagram.Name + "|" + diagram.ModelElement.Id.ToString("B");
        }

        /// <summary>
        /// Creates from physical view.
        /// </summary>
        /// <param name="physicalView">The physical view.</param>
        /// <returns></returns>
        public static MultiViewContext CreateFromPhysicalView(string physicalView)
        {
            Guard.ArgumentNotNullOrEmptyString(physicalView, "physicalView");
            string[] parts = physicalView.Split('|');
            if (parts.Length == 1)
                return new MultiViewContext { DiagramName = parts[0] };
            else
                return new MultiViewContext { DiagramName = parts[0], RootElementId=new Guid(parts[1]) };
        }
    }
}
